// pages/video/video.js
function getRandomColor() {
  let rgb = []

  for (let i = 0; i < 3; ++i) {
    let color = Math.floor(Math.random() * 256).toString(16)
    color = (color.length == 1) ? '0' + color : color
    rgb.push(color)
  }
  return '#' + rgb.join('')
}

Page({
  data: {
    list: [
      {
        id: '0',
        title: '传统柴窑匠人邵志彤',
        text: '传承古法柴窑之火',
        imgUrl: 'https://pic.rmb.bdstatic.com/2b131fb8729e75538c0308e3fae7d3e6.jpeg?x-bce-process=image/quality,q_80/resize,m_fill,w_660,h_370',
        videoUrl: 'https://vd4.bdstatic.com/mda-jgfdkn10ifc9xewx/sc/mda-jgfdkn10ifc9xewx.mp4'
      },
      {
        id: '1',
        title: '青花梅瓶匠人熊光鑫',
        text: '梅林煮酒论英雄',
        imgUrl: 'https://pic.rmb.bdstatic.com/2f2fbb752845761eff12fc2c7e3441a3.jpeg?x-bce-process=image/quality,q_80/resize,m_fill,w_660,h_370',
        videoUrl: 'https://vd3.bdstatic.com/mda-jgndw472htnmva9x/sc/mda-jgndw472htnmva9x.mp4'
      },
      {
        id: '2',
        title: '粉彩扒花匠人 张 立',
        text: '粉彩扒花的针尖艺术',
        imgUrl: 'https://pic.rmb.bdstatic.com/c9773fa8dc749a8e6527a3d127d89022.jpeg?x-bce-process=image/quality,q_80/resize,m_fill,w_660,h_370',
        videoUrl: 'https://vd3.bdstatic.com/mda-jgvfwwprpi0dgs1k/sc/mda-jgvfwwprpi0dgs1k.mp4'
      },
      {
        id: '3',
        title: '珐琅彩釉匠人覃淑琴',
        text: '智慧与艺术并存',
        imgUrl: 'https://pic.rmb.bdstatic.com/77ba2611edac539cd5c7a5ffa0557d83.jpeg?x-bce-process=image/quality,q_80/resize,m_fill,w_660,h_370',
        videoUrl: 'https://vd3.bdstatic.com/mda-jh5dwgi8qb0umr14/sc/mda-jh5dwgi8qb0umr14.mp4'
      },
      {
        id: '4',
        title: '陶瓷雕塑匠人谢成龙',
        text: '手工陶瓷的泥性之美',
        imgUrl: 'https://pic.rmb.bdstatic.com/b61b86ecce7b4a90dfc49c19db07c0cd.jpeg?x-bce-process=image/quality,q_80/resize,m_fill,w_660,h_370',
        videoUrl: 'https://vd3.bdstatic.com/mda-jhjnzbv57fq40rkz/sc/mda-jhjnzbv57fq40rkz.mp4'
      }
    ],
    danmuTxt:''
  },
  skipVideo1: function () {
    wx.redirectTo({
      url: '/pages/v2/v2',
      success(){
        console.log('视频页面2跳转成功')
      },
      fail: err=> {
        console.log(err)
      },
    })
  },
  skipVideo2: function () {
    wx.redirectTo({
      url: '/pages/v3/v3',
      success(){
        console.log('视频页面3跳转成功')
      },
      fail: err=> {
        console.log(err)
      },
    })
  },
  skipVideo3: function () {
    wx.redirectTo({
      url: '/pages/v4/v4',
      success(){
        console.log('视频页面4跳转成功')
      },
      fail: err=> {
        console.log(err)
      },
    })
  },
  skipVideo4: function () {
    wx.redirectTo({
      url: '/pages/v5/v5',
      success(){
        console.log('视频页面5跳转成功')
      },
      fail: err=> {
        console.log(err)
      },
    })
  },
  onLoad: function (options) {
    this.videoCtx=wx.createVideoContext('myVideo')
  },
  playVideo: function (e) {
    this.videoCtx.stop()
    // 停止播放之前正在播放的视频
    this.setData({
      src: e.currentTarget.dataset.url
    })
    // 更新视频地址
    this.videoCtx.play()
    // 播放新的视频
  },
  getDanmu:function(e) {
    this.inputText=e.detail.value
  },
  sendDanmu:function(){
    this.videoCtx.sendDanmu({
      text:this.inputText,
      color:getRandomColor()
    })
  },
  inputText:'',
})